import socket
import time
import json
import struct
import math
# 配置服务器
host = '127.0.0.1'
port = 12348
addr = (host, port)
byte = 1024
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)


dt = 1/30
yawTeriod = math.pi/10
x0 = 0.0
y0 = 0.0
z0 = 0.0
yaw = 0.0
pitch = 0.0
roll = 0.0

dpitch = yawTeriod*dt

while True:
    time.sleep(dt)
    pitch += dpitch
    pitch = pitch % (math.pi*2)
    text = struct.pack('6f', x0, y0, z0, yaw, pitch, roll)
    sock.sendto(text, addr)

    # data = time.strftime("100$121$231$%H:%M:%S:00", time.localtime())
    # data = "hello"
    # data = json.dumps(dataDict)
    #data = time.strftime("%H:%M:%S", time.localtime())
    # text = data.encode('utf-8')

sock.close()
